// pages/order/orderexpress/orderexpress.js
const app = new getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    Base: '',
    express_info: {}, //订单物流信息
    packet_info: {}, //包裹物流信息
    express: {} //快递物流信息
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    let base = app.globalData.siteBaseUrl;
    let order_id = options.id;

    app.sendRequest({
      url: 'api.php?s=order/orderExpress',
      data: {
        orderId: order_id
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      method: "POST",
      success: function (res) {
        let code = res.code;
        if (code == 0) {
          let express_info = res.data.goods_packet_list;

          for (let index in express_info){
            if(index == 0){
              express_info[index].status = 1
            }else{
              express_info[index].status = 0
            }
          }
          that.setData({
            Base: base,
            express_info: express_info,
            packet_info: express_info[0]
          })
        }
        console.log(res)
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },

  /**
   * 查询物流信息
   */
  getExpressInfo: function (that, express_id){
    app.sendRequest({
      url: 'api.php?s=order/getOrderGoodsExpressMessage',
      data: {
        express_id: express_id
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      method: "POST",
      success: function (res) {
        let code = res.code;
        if (code == 0) {
          that.setData({
            express: res.data
          })
        }
      }
    });
  },

  /**
   * 导航选择
   */
  navClick: function(event){
    let that = this;
    let index = event.currentTarget.dataset.index;
    let express_info = that.data.express_info;
    
    for(let key in express_info){
      express_info[key].status = 0;
    }
    
    express_info[index].status = 1;

    that.setData({
      express_info: express_info,
      packet_info: express_info[index],
    })
  }
})